#ifndef LOGINWIDGET_H
#define LOGINWIDGET_H

#include <QWidget>

class QGridLayout;
class QLineEdit;
class QPushButton;
class QLabel;
class VerifyCodeWidget;

class LoginWidget : public QWidget
{
    Q_OBJECT
public:
    explicit LoginWidget(QWidget* parent = nullptr);

private:
    void initAccountLoginWidget();
    void initPhoneLoginWidget();

    void switchAccountLoginWidget();
    void switchPhoneLoginWidget();

    void switchLoginMode();
    void swithRegisterMode();

    void clearLayout();
    void claerLineEdit();

    void onClickedBySubmitBtn();
    void onClickedBySendVerifyCodeBtn();

    void loginDoneHandle(bool ok, const QString& reason);
    void registerDoneHandle(bool ok, const QString& reason);
    void getVerifyCodeDoneHandle();

    static QLineEdit* createLineEdit(const QString& text);
    static QString getSwitchBtnStyle();
    static QString getSubmitBtnStyle();

private:
    bool isLoginMode;
    bool isAccountLogin;

    QGridLayout* layout;

    QLabel* titleLabel;

    QLineEdit* usernameEdit;
    QLineEdit* passwordEdit;
    QLineEdit* passwordConfirmEdit;
    QLineEdit* phoneEdit;

    QLineEdit* verifyCodeEdit;
    VerifyCodeWidget* verifyCodeWidget;         // 图形验证码
    QPushButton* sendVerifyCodeBtn;     // 短信验证码按钮

    QPushButton* submitBtn;
    QPushButton* switchLoginModeBtn;
    QPushButton* switchWidgetModeBtn;

    QTimer* countdownTimer = nullptr;
    QString currentPhone;   // 记录发送验证码的手机号

signals:
};

#endif
